
var server_host = 'http://www.ziranm.cn';

var oAuthUrl = server_host + '/wxOAuth';
var platformInfoUrl = server_host + '/wxPlatformInfo';

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

function findElement(arr, propName, propValue) {
    for (var i = 0; i < arr.length; i++)
        if (arr[i][propName] == propValue)
            return arr[i];
}

function jsonObjToBase64(json) {
    return btoa(encodeURIComponent(JSON.stringify(json)));
}

function base64TojsonObj(base64) {
    return eval('(' + decodeURIComponent(atob(base64)) + ')');
}

function stripHtml(html) {
    var tmp = document.createElement("DIV");
    tmp.innerHTML = html;
    return tmp.textContent || tmp.innerText || "";
}

function oauth(appId, callback) {
    $.ajax({
        type: "POST",
        url: oAuthUrl,
        data: {
            appId: appId
        },
        success: function(data) {
            callback(data);
        }
    });
}

$(document).ready(function() {
    //绑定公共事件
    $('.head-contain ul li').on('mouseover', function(){
        $(this).children('.xiala').css('display','block')
    })
    $('.head-contain ul li').on('mouseout', function(){
        $(this).children('.xiala').css('display','none')
    })
    $('.phone-contain').on('mouseover',function(){
        $('.phone-detail').css('display','block')
    })
    $('.phone-contain').on('mouseout',function(){
        $('.phone-detail').css('display','none')
    })
    $('.wx-contain').on('mouseover',function(){
        $('.wx-detail').css('display','block')
    })
    $('.wx-contain').on('mouseout',function(){
        $('.wx-detail').css('display','none')
    })
    $('.arrow').on('click',function(){
        $('html,body').animate({scrollTop: '0px'}, 300);
    })
    $(window).scroll(function(){
       if($(document).scrollTop()>0){
        $('.contact-way .arrow').css('display','block')
       }else {
        $('.contact-way .arrow').css('display','none')
       }
    })
    var openId = getParameterByName('openId');
    var appId = getParameterByName('appId');
    var start = function() {
        if (typeof(app) !== 'undefined') {
            clearInterval(timer);
            if (!!openId) {
                sessionStorage.setItem('openId', openId);
                app.bootstrap(openId);
            } else {
                app.bootstrap(sessionStorage.getItem('openId'));
            }

            if (!!appId) {
                sessionStorage.setItem('appId', appId);
            } else {
                appId = sessionStorage.getItem('appId');
            }


            var titleName = sessionStorage.getItem('titleName');
            if (!titleName) {
                $.ajax({
                    type: "POST",
                    url: platformInfoUrl,
                    data: {
                        appId: appId
                    },
                    success: function(data) {
                        titleName = data.obj.name;
                        sessionStorage.setItem('titleName', titleName);
                        document.getElementsByTagName('title')[0].innerHTML = titleName;
                    }
                });
            } else {
                document.getElementsByTagName('title')[0].innerHTML = titleName;
            }

        }
    }

});

var Spinner = {
    start: function() {
        $(document.body).css('overflow', 'hidden');
        $('#spinner').show();
    },
    stop: function() {
        $(document.body).css('overflow', 'auto');
        $('#spinner').hide();
    }
}